package smm.springboot_ftl.action;

import java.util.Arrays;
import java.util.List;

import org.apache.ibatis.session.RowBounds;

//import lombok.extern.slf4j.Slf4j;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import smm.springboot_ftl.bean.Alipay;
import smm.springboot_ftl.bean.AlipayExample;
import smm.springboot_ftl.bean.AlipayExample.Criteria;
import smm.springboot_ftl.mapper.AlipayDAO;

//@Slf4j
@RestController
public class AlipayController {
	private static final Logger LOG = LoggerFactory.getLogger(AlipayController.class);
	@Autowired
	private AlipayDAO alipayDAO;

	@GetMapping("/info/{id}")
	public ResponseEntity<Alipay> list(@PathVariable("id") Long id) {
		Alipay selectByPrimaryKey = alipayDAO.selectByPrimaryKey(id);
		return ResponseEntity.ok(selectByPrimaryKey);
	}

	@GetMapping("/examle")
	public ResponseEntity<List<Alipay>> examle() {
		System.out.println(LOG.isDebugEnabled());
		LOG.debug("---> debug start! <------");
		LOG.info("---> info start! <------");
		LOG.warn("---> warn start! <------");
		LOG.error("---> error start! <------");
		AlipayExample alipayExample = new AlipayExample();
		Criteria createCriteria = alipayExample.createCriteria();
		createCriteria.andAmountBetween(Short.valueOf("1"), Short.valueOf("10"));
		alipayExample.setOrderByClause(" amount asc");
		// createCriteria.andIdIn(Arrays.asList(1l, 10l, 11l));
		// alipayExample.setLimit(20);
		// alipayExample.setOffset(10l);

		List<Alipay> selectByPrimaryKey = alipayDAO.selectExamle(alipayExample);
		return ResponseEntity.ok(selectByPrimaryKey);
	}

	@GetMapping("/list")
	public ResponseEntity<List<Alipay>> list() {
		LOG.debug("---> debug start! <------");
		LOG.info("---> info start! <------");
		List<Alipay> selectByPrimaryKey = alipayDAO.selectAll();
		return ResponseEntity.ok(selectByPrimaryKey);
	}
	@GetMapping("/page")
	public ResponseEntity<List<Alipay>> page() {
		LOG.debug("---> debug start! <------");
		LOG.info("---> info start! <------");
		List<Alipay> selectByPrimaryKey = alipayDAO.selectPageAll(new RowBounds(10, 20));
		return ResponseEntity.ok(selectByPrimaryKey);
	}
	@GetMapping("/page/{pageNum}/{pageSize}")
	public ResponseEntity<PageInfo<Alipay>> pageLimit(@PathVariable("pageNum")  int pageNum, @PathVariable("pageSize") int pageSize) {
		LOG.debug("---> debug start! <------");
		LOG.info("---> info start! <------");
		// 第几页， 页大小
		PageHelper.startPage(pageNum, pageSize);
		Page<Object> localPage = PageHelper.getLocalPage();
		List<Alipay> list = alipayDAO.selectAll();
		PageInfo<Alipay> page = new PageInfo<Alipay>(list);
		return ResponseEntity.ok(page);
	}
	
}
